<html>
<head>
    <style>
        * {
            list-style-type: none;
        }

        img {
            width: 150px;
            height: 150px;
        }

        #menu > ul > li > a {
            background-color: #D24D57;
            color: #FFF;
            width: 200px;
            height: 50px;
            font-size: 30px;
            line-height: 50px;
            text-align: center;
            cursor: pointer; /* 鼠标放上去有个小手 */
            text-decoration: none;
        }

        #menu {
            position: fixed;
            top: 10px;
            right: 100px;
        }
        #menu .active{
            background-color: green;
            color: whitesmoke;
        }
    </style>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<div id="menu">
    <ul>
        <li><a href="#item_1" class="active" >1F 键盘1</a></li>
        <li><a href="#item_2">2F 键盘2</a></li>
        <li><a href="#item_3">3F 键盘3</a></li>
        <li><a href="#item_4">4F SSD</a></li>
        <li><a href="#item_5">5F 游戏</a></li>
    </ul>
</div>

<div id="content">
    <ul id="item_1" class="item">

        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201903/03/154513rrd8d9dir52l1r25.png" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201903/03/154513rrd8d9dir52l1r25.png" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201903/03/154513rrd8d9dir52l1r25.png" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201903/03/154513rrd8d9dir52l1r25.png" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201903/03/154513rrd8d9dir52l1r25.png" alt=""></a></li>
    </ul>

    <ul id="item_2" class="item">
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122551t33z0mmo7g090o27.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122551t33z0mmo7g090o27.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122551t33z0mmo7g090o27.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122551t33z0mmo7g090o27.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122551t33z0mmo7g090o27.jpg" alt=""></a></li>
    </ul>

    <ul id="item_3" class="item">
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122631v3tp3yadv6vp3jjr.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122631v3tp3yadv6vp3jjr.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122631v3tp3yadv6vp3jjr.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122631v3tp3yadv6vp3jjr.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/122631v3tp3yadv6vp3jjr.jpg" alt=""></a></li>
    </ul>

    <ul id="item_4" class="item">
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/28/115144thw1tklkqrlzqtcl.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/28/115144thw1tklkqrlzqtcl.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/28/115144thw1tklkqrlzqtcl.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/28/115144thw1tklkqrlzqtcl.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/28/115144thw1tklkqrlzqtcl.jpg" alt=""></a></li>
    </ul>

    <ul id="item_5" class="item">
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/1225427jegpzezfxjjf1f1.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/1225427jegpzezfxjjf1f1.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/1225427jegpzezfxjjf1f1.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/1225427jegpzezfxjjf1f1.jpg" alt=""></a></li>
        <li><a href=""><img src="http://attach.zhiyoo.com/forum/201902/27/1225427jegpzezfxjjf1f1.jpg" alt=""></a></li>
    </ul>
</div>

</body>

<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
    $(document).ready(function () {




        $(window).scroll(function () {
          var top = $(document).scrollTop();  // 整个网页向下滚动的距离(滚动条的距离)
          // console.log("网页向下滚动了: " + parseInt(top));
          var menu = $('#menu');

            var items = $("#content").find('.item');
            // console.log(items);

            var currentid = "";  // 当前楼层item 的 id
            items.each(function () {
                var m = $(this);
                var itemTop = m.offset().top;       // 得到每个item距离顶部的距离
                console.log("**********************************");
                console.log(m.attr("id") + "偏移量:>" + parseInt(itemTop));
                console.log("**********************************");
                if ((top+100) > itemTop){
                    currentid = "#" + m.attr("id");
                    // console.log(currentid);    // 当前楼层item 的 id
                }else {
                    return false;
                }
            });


            var currentlink = menu.find('.active');     // 被选中的条目

            if(currentid && currentlink.attr("href") != currentid){
                currentlink.removeClass('active');
                menu.find("[href=" + currentid + "]").addClass("active");
            }



        })
    })

</script>

</html>